package com.example.monitor.controller;

import com.example.monitor.model.DTO.SystemSettingsDTO;
import com.example.monitor.model.VO.ResultVO;
import com.example.monitor.model.VO.SystemSettingsUpdateVO;
import com.example.monitor.model.VO.SystemSettingsVO;
import com.example.monitor.service.SystemSettingsService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/settings")
@RequiredArgsConstructor
public class SettingsController {

    private final SystemSettingsService settingsService;

    @GetMapping
    public ResultVO<SystemSettingsVO> getSystemSettings() {
        return settingsService.getSystemSettings();
    }

    @PutMapping
    @PreAuthorize("hasRole('ADMIN')")
    public ResultVO<Void> updateSystemSettings(
            @Valid @RequestBody SystemSettingsUpdateVO updateVO) {

        // 执行更新
        settingsService.updateSystemSettings(updateVO);

        // 返回成功响应
        return ResultVO.success("系统设置更新成功");
    }
}